package start.demo01.datatype.json.entity.editor.jsonEditor;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import start.demo01.datatype.json.constant.Constant;
import start.demo01.datatype.json.interfaces.JSONEditor;

//字段删减
public class JSONRemoveEditor extends JSONEditor {

    public JSONRemoveEditor(String args) {
        super(args);
    }
    {
        name="REMOVE";
    }
    @Override
    protected void operationObject(JSONObject object, String key) {
        object.remove(key);
    }

    @Override
    protected void operationArray(JSONArray array, int index) {
        array.remove(index);
    }

    @Override
    protected void operation(JSONObject object) {
        if(args.equals(Constant.F)){
            object.clear();
        }
        for (String k : args.split(",")) {
            object.remove(k);
        }
    }
}
